import { createStore } from "vuex";

export default createStore({
  state: {
    title: "首页",
    title2: "",
    user:{
       userFlag: false,
       userId:123,
       loginTime:'',
       username:localStorage.getItem('username'),
       doctorFlag:'user',
    }
  },
mutations: {
  changeLoginTime(state,payload){
    const timestamp: any = payload
      const dateObj: any = new Date( timestamp );
      const year: any = dateObj.getYear() + 1900;
      const month: any = dateObj.getMonth() + 1;
      const theDate: any = dateObj.getDate();
      const hour: any = dateObj.getHours();
      const minute: any = dateObj.getMinutes();
      const second: any = dateObj.getSeconds();
      state.user.loginTime = year +"-"+ month +"-" + theDate + " "+ hour +":"+ minute +":"+ second
   localStorage.setItem('loginTime',state.user.loginTime)
console.log(payload);

  },
  changeTitle2(state, payload) {
  console.log( payload);
    state.title = payload[0].titel;
    state.title2 = payload[0].innerTitel;
  },
  changeUserFlag(state, payload) {
    if (payload) {
      state.user.userFlag = true;
      localStorage.setItem('userFlag','1')
    }
  },
  changeUserName(state,payload){
    console.log(payload);
    localStorage.setItem('username',payload)
    state.user.username = payload
  }
},
actions: {},
modules: {},
})
